# -*- coding: utf-8 -*-
from selenium import  webdriver
from selenium.webdriver.firefox.webdriver import  Options
from scrapy.http import  HtmlResponse
from boss.proxy_boss import ProxyMiddleware
from time import sleep


class Get_bossMiddleware():
    proxy=ProxyMiddleware()
    proxise='--proxy-server='+proxy.ip
    print(proxise)
    def __init__(self):
        self.opt=Options()
        #self.opt.add_argument('--headless')
        self.opt.add_argument('--disable-gpu')
        self.opt.add_argument(self.proxise)
        self.bro=webdriver.Firefox(firefox_options=self.opt)

    def process_request(self, request, spider):
        self.bro.implicitly_wait(10)
        self.bro.get(request.url)
        sleep(2)
        news_reques=self.bro.page_source
        response = HtmlResponse(url=self.bro.current_url, body=news_reques, request=request, encoding='utf-8')
        return response

    def __del__(self):
        self.bro.quit()